import { eLayoutType, RoutesService } from '@abp/ng.core';
import { eIdentityPolicyNames, eIdentityRouteNames } from '@abp/ng.identity/config';
import { eThemeSharedRouteNames } from '@abp/ng.theme.shared';
import { eRoutePaths } from '../enums';
import { APP_INITIALIZER } from '@angular/core';

export const IDENTITY_ROUTE_PROVIDERS = [
  { provide: APP_INITIALIZER, useFactory: configureRoutes, deps: [RoutesService], multi: true },
];

export function configureRoutes(routes: RoutesService) {
  return () => {
    routes.add([
      {
        path: undefined,
        name: eIdentityRouteNames.IdentityManagement,
        parentName: eThemeSharedRouteNames.Administration,
        iconClass: 'solution',
        layout: eLayoutType.application,
        order: 1,
      },
      {
        path: `/${eRoutePaths.Identity}/roles`,
        name: eIdentityRouteNames.Roles,
        parentName: eIdentityRouteNames.IdentityManagement,
        requiredPolicy: 'Menus.Administration.IdentityManagement.Roles',
        order: 1,
      },
      {
        path: `/${eRoutePaths.Identity}/user-detail`,
        name: eIdentityRouteNames.Users,
        parentName: eIdentityRouteNames.IdentityManagement,
        requiredPolicy: 'Menus.Administration.IdentityManagement.Users',
        order: 2,
      },
      {
        path: `/${eRoutePaths.Identity}/user-list`,
        name: 'Menus:UserList',
        parentName: eIdentityRouteNames.IdentityManagement,
        requiredPolicy: 'Menus.Administration.IdentityManagement.Users',
        invisible: true,
        order: 3,
      },
    ]);
  };
}
